From a7d024ef9b9f535150db117228a81f046e63eed7 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Wed, 29 Nov 2006 00:25:27 +0000 Subject: [PATCH] Remove route switch (-r) dependency. Fix id output format. Write same id's in route and marks. Update coastexp reference files. --- coastexp.c | 136 ++++++++++++++++++++++++++++------------ reference/coastexp.ref2 | 76 +++++++++++----------- reference/coastexp.ref3 | 103 +++++++++++++----------------- reference/coastexp.ref4 | 97 ++++++++++++++++------------ 4 files changed, 233 insertions(+), 179 deletions(-) diff --git a/coastexp.c b/coastexp.c index acb70996e..a99eac16b 100755 --- a/coastexp.c +++ b/coastexp.c @@ -95,7 +95,9 @@ ce_add_mark_to_route(ce_route *route, ce_mark *mark) static void ce_free_mark(ce_mark *mark) { - xfree(mark->id); + dequeue(&mark->Q); + if (mark->id) + xfree(mark->id); if (mark->created) xfree(mark->created); xfree(mark); @@ -115,6 +117,16 @@ ce_free_route(ce_route *route) // Don't free the waypoint since this is done elsewhere } +/* Allocate a mark */ +static ce_mark * +ce_alloc_mark(const waypoint *wpt, const char *id) +{ + ce_mark *res = xcalloc(sizeof(ce_mark), 1); + res->id = (char *) id; + res->wp = (waypoint *) wpt; + return res; +} + #if !HAVE_LIBEXPAT void ce_rd_init(const char *fname) @@ -145,18 +157,14 @@ ce_start(void *data, const XML_Char *xml_el, const XML_Char **xml_attr) // Create a CE route object and add it to the list of routes currentRoute = (ce_route *) xcalloc(sizeof (ce_route), 1); currentRoute->id=xstrdup(ap[1]); - if (doing_rtes) - currentRoute->r = route_head_alloc(); + currentRoute->r = route_head_alloc(); QUEUE_INIT(¤tRoute->ce_mark_head); - if (doing_rtes) - ce_add_route(currentRoute); + ce_add_route(currentRoute); } } } else if (0 == strcmp(el, "Mark")) { inMark = 1; - currentMark = (ce_mark *) xcalloc(sizeof (ce_mark), 1); - currentMark->wp = NULL; - currentMark->used = 0; + currentMark = ce_alloc_mark(NULL, NULL); ce_add_mark(currentMark); for (ap = attr; *ap; ap+=2) { if (0 == strcmp(ap[0], "id")) { @@ -178,9 +186,7 @@ ce_end(void *data, const XML_Char *xml_el) { const char *el = xml_convert_to_char_string(xml_el); if (0 == strcmp(el, "Route")) { - if (!doing_rtes) - ce_free_route(currentRoute); - inRoute = 0; + inRoute = 0; /* ??? */ } else if (0 == strcmp(el, "Mark")) inMark = 0; @@ -214,10 +220,7 @@ ce_cdata(void *dta, const XML_Char *xml_s, int len) if (inRoute) { // We are processing the marks in a route so create a CE mark object // and add it to the current route - ce_mark *mark = (ce_mark *) xcalloc(sizeof (ce_mark), 1); - mark->id = xstrdup(s); - mark->created = NULL; - mark->wp = NULL; + ce_mark *mark = (ce_mark *) ce_alloc_mark(NULL, xstrdup(s)); ce_add_mark_to_route(currentRoute, mark); } } else if (0 == strcmp(element, "Position")) { @@ -284,7 +287,6 @@ ce_cdata(void *dta, const XML_Char *xml_s, int len) } } else if (inRoute) { - if (doing_rtes) currentRoute->r->rte_name = xstrdup(s); } } else if (0 == strcmp(element, "Description")) { @@ -397,7 +399,6 @@ ce_remove_used_marks(void) ce_mark *mark = (ce_mark *) elem; if (mark->used) { - dequeue(elem); if (mark->wp) waypt_free(mark->wp); ce_free_mark(mark); @@ -444,11 +445,9 @@ ce_rd_deinit(void) */ queue *elem, *tmp; - if (doing_rtes) { - ce_fix_route_mark_waypoints(); + ce_fix_route_mark_waypoints(); ce_check_route_names(); - ce_remove_used_marks(); - } + ce_remove_used_marks(); // Log results if (global_opts.debug_level > 1) @@ -457,7 +456,6 @@ ce_rd_deinit(void) // Add routes to GPSBabel QUEUE_FOR_EACH(&ce_route_head, elem, tmp) { ce_route *route = (ce_route *) elem; - if (doing_rtes) { queue *elem2, *tmp2; route_add_head(route->r); QUEUE_FOR_EACH(&route->ce_mark_head, elem2, tmp2) { @@ -467,7 +465,6 @@ ce_rd_deinit(void) else printf("Undefined mark: %s\n", mark->id); } - } ce_free_route(route); } @@ -495,6 +492,7 @@ ce_wr_init(const char *fname) xml_buffer = xcalloc(MY_XBUF, 1); ofd = gbfopen(fname, "w", MYNAME); + srand(gpsbabel_now); } void @@ -541,11 +539,9 @@ ce_gen_uuid(void) static void ce_route_hdr(const route_head *rte) { - if (doing_rtes) { - sprintf(xml_buffer, "{%s}", ce_gen_uuid()); - write_xml_entity_begin2(ofd, "\t", "Route", "created", ce_gen_current_time(), "id", xml_buffer); - write_xml_entity_begin0(ofd, "\t\t", "Marks"); - } + sprintf(xml_buffer, "{%s}", ce_gen_uuid()); + write_xml_entity_begin2(ofd, "\t", "Route", "created", ce_gen_current_time(), "id", xml_buffer); + write_xml_entity_begin0(ofd, "\t\t", "Marks"); } /* Generate route body XML */ @@ -554,11 +550,11 @@ ce_route_disp(const waypoint *waypointp) { char *uuid = ce_gen_uuid(); char *id = xcalloc(strlen(uuid)+3, 1); + sprintf(id, "{%s}", uuid); - currentMark = (ce_mark *) xcalloc(sizeof (ce_mark), 1); - currentMark->id = id; - currentMark->wp = (waypoint *) waypointp; + currentMark = ce_alloc_mark(waypointp, id); ENQUEUE_TAIL(&ce_mark_head, ¤tMark->Q); + gbfprintf(ofd, "\t\t\t%s\n", id); // CE's departure from XML standard! } @@ -566,11 +562,9 @@ ce_route_disp(const waypoint *waypointp) static void ce_route_tlr(const route_head *rte) { - if (doing_rtes) { - write_xml_entity_end(ofd, "\t\t", "Marks"); - write_optional_xml_entity(ofd, "\t\t", "Name", rte->rte_name); - write_xml_entity_end(ofd, "\t", "Route"); - } + write_xml_entity_end(ofd, "\t\t", "Marks"); + write_optional_xml_entity(ofd, "\t\t", "Name", rte->rte_name); + write_xml_entity_end(ofd, "\t", "Route"); } /* Generate waypoint body XML */ @@ -595,13 +589,59 @@ ce_waypt_pr(const waypoint *wp) write_optional_xml_entity(ofd, "\t\t", "Name", wp->shortname); } -/* Generate a standalone mark XML */ +static char * +ce_find_uuid(const waypoint *wpt) +{ + queue *elem, *tmp; + + QUEUE_FOR_EACH(&ce_mark_head, elem, tmp) { + ce_mark *mark = (ce_mark *) elem; + if (mark->wp == wpt) { + return mark->id; + } + } + return NULL; +} + +static waypoint * +ce_find_wpt(const waypoint *wpt) +{ + queue *elem, *tmp; + + QUEUE_FOR_EACH(&ce_mark_head, elem, tmp) { + ce_mark *mark = (ce_mark *) elem; + if ((mark->wp->shortname == wpt->shortname) && + (mark->wp->latitude == wpt->latitude) && + (mark->wp->longitude == wpt->longitude)) + return mark->wp; + } + return NULL; +} + +/* Generate a mark XML; look for created id's */ static void ce_mark_pr(const waypoint *wp) { + char *id; + + if (inRoute) { + id = ce_find_uuid(wp); + if (id == NULL) { + sprintf(xml_buffer, "{%s}", ce_gen_uuid()); + id = xml_buffer; + } + } + /* Have we seen and written the (nearly) same waypoint ? */ + else if (ce_find_wpt(wp) != NULL) return; + else { + ce_mark *mark = ce_alloc_mark(wp, NULL); + ENQUEUE_TAIL(&ce_mark_head, &mark->Q); + sprintf(xml_buffer, "{%s}", ce_gen_uuid()); + id = xml_buffer; + } write_xml_entity_begin2(ofd, "\t", "Mark", - "created", ce_gen_creation_time(wp->creation_time), - "id", ce_gen_uuid()); + "created", ce_gen_creation_time(wp->creation_time), + "id", id); ce_waypt_pr(wp); write_xml_entity_end(ofd, "\t", "Mark"); } @@ -611,9 +651,21 @@ static void ce_marks_pr(void) { queue *elem, *tmp; + QUEUE_FOR_EACH(&ce_mark_head, elem, tmp) { ce_mark *mark = (ce_mark *) elem; ce_mark_pr(mark->wp); + } +} + +/* Release all generated marks */ +static void +ce_marks_flush_all(void) +{ + queue *elem, *tmp; + + QUEUE_FOR_EACH(&ce_mark_head, elem, tmp) { + ce_mark *mark = (ce_mark *) elem; ce_free_mark(mark); } } @@ -634,10 +686,14 @@ ce_write(void) ce_gen_current_time()); write_xml_entity(ofd, "\t", "Name", "Navigation Objects"); + inRoute = 1; route_disp_all(ce_route_hdr, ce_route_tlr, ce_route_disp); ce_marks_pr(); + inRoute = 0; + waypt_disp_all(ce_mark_pr); - + ce_marks_flush_all(); + write_xml_entity_end(ofd, "", "NavObjectCollection"); } diff --git a/reference/coastexp.ref2 b/reference/coastexp.ref2 index d5a7be89e..b9385cbde 100644 --- a/reference/coastexp.ref2 +++ b/reference/coastexp.ref2 @@ -16,155 +16,155 @@ Into The Bay - + 37.763290 N 122.282580 W SFBALBAY - + 37.751613 N 122.339028 W SFBAY001 - + 37.817420 N 122.394305 W SFBAY002 - + 37.819339 N 122.478302 W SFGGBRDG - + 37.773033 N 122.605838 W SFCHNL01 - + 37.518860 N 122.529914 W HMCOLREF - + 37.482348 N 122.507704 W HMPILL01 - + 37.475062 N 122.488531 W HMPILLPT - + 37.476448 N 122.475800 W HMPILL02 - + 37.495102 N 122.483927 W HMPILL03 - + 37.229349 N 122.441589 W PESCDR01 - + 37.183397 N 122.411904 W PIGEON01 - + 37.090736 N 122.348775 W ANONUV01 - + 36.929502 N 122.113725 W SCRUZ01 - + 36.934235 N 122.022130 W SCRUZ02 - + 36.960666 N 122.024734 W SCRUZENT - + 36.581344 N 121.995411 W CYPRSSPT - + 36.301110 N 121.919097 W PTSUR - + 36.238177 N 121.855209 W COOPERPT - + 36.225175 N 121.801314 W PFEIFENT - + 36.230449 N 121.797444 W PFEIFANC - + 35.879801 N 121.498947 W SANMRT01 - + 35.652801 N 121.308485 W PDRSBLNC - + 35.623297 N 121.185920 W SNSMNENT - + 35.640478 N 121.183772 W SNSMNANC - + 35.572353 N 121.152797 W CAMBRIA - + 35.449214 N 121.020825 W PTESTERO - + 35.216602 N 120.928391 W PTBUCHON - + 34.883361 N 120.684631 W PTSAL01 - + 34.884641 N 120.652026 W PTSALENT - + 34.896555 N 120.649124 W PTSALANC - + 34.758180 N 120.642516 W PURSMAPT - + 34.572579 N 120.663636 W PTARGLLO - + 34.113844 N 120.492630 W SANMGL01 - + 34.029483 N 120.471409 W SANMGL02 - + 34.019184 N 120.444197 W SANMGL03 - + 34.023478 N 120.438209 W ADCOVENT - + 34.028615 N 120.439696 W ADCOVANC diff --git a/reference/coastexp.ref3 b/reference/coastexp.ref3 index fe1d2e3f9..86bab53b1 100644 --- a/reference/coastexp.ref3 +++ b/reference/coastexp.ref3 @@ -7,60 +7,6 @@ xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> - - - SFBALBAY - SFBALBAY - SFBALBAY - - - - SFBAY001 - SFBAY001 - SFBAY001 - - - - SFBAY002 - SFBAY002 - SFBAY002 - - - - SFGGBRDG - SFGGBRDG - SFGGBRDG - - - - SFCHNL01 - SFCHNL01 - SFCHNL01 - - - - HMCOLREF - HMCOLREF - HMCOLREF - - - - HMPILL01 - HMPILL01 - HMPILL01 - - - - HMPILL02 - HMPILL02 - HMPILL02 - - - - HMPILL03 - HMPILL03 - HMPILL03 - PESCDR01 @@ -97,12 +43,6 @@ xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/ SCRUZENT SCRUZENT - - - HMPILLPT - HMPILLPT - HMPILLPT - CYPRSSPT @@ -235,4 +175,47 @@ xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/ ADCOVANC ADCOVANC + + Into The Bay + + + SFBALBAY + + + + SFBAY001 + + + + SFBAY002 + + + + SFGGBRDG + + + + SFCHNL01 + + + + HMCOLREF + + + + HMPILL01 + + + + HMPILLPT + + + + HMPILL02 + + + + HMPILL03 + + diff --git a/reference/coastexp.ref4 b/reference/coastexp.ref4 index 20faa6aaa..b9385cbde 100644 --- a/reference/coastexp.ref4 +++ b/reference/coastexp.ref4 @@ -1,155 +1,170 @@ Navigation Objects - + + + {10111213-1415-1617-1819-1a1b1c1d1e1f} + {20212223-2425-2627-2829-2a2b2c2d2e2f} + {30313233-3435-3637-3839-3a3b3c3d3e3f} + {40414243-4445-4647-4849-4a4b4c4d4e4f} + {50515253-5455-5657-5859-5a5b5c5d5e5f} + {60616263-6465-6667-6869-6a6b6c6d6e6f} + {70717273-7475-7677-7879-7a7b7c7d7e7f} + {80818283-8485-8687-8889-8a8b8c8d8e8f} + {90919293-9495-9697-9899-9a9b9c9d9e9f} + {a0a1a2a3-a4a5-a6a7-a8a9-aaabacadaeaf} + + Into The Bay + + 37.763290 N 122.282580 W SFBALBAY - + 37.751613 N 122.339028 W SFBAY001 - + 37.817420 N 122.394305 W SFBAY002 - + 37.819339 N 122.478302 W SFGGBRDG - + 37.773033 N 122.605838 W SFCHNL01 - + 37.518860 N 122.529914 W HMCOLREF - + 37.482348 N 122.507704 W HMPILL01 - + + 37.475062 N 122.488531 W + HMPILLPT + + 37.476448 N 122.475800 W HMPILL02 - + 37.495102 N 122.483927 W HMPILL03 - + 37.229349 N 122.441589 W PESCDR01 - + 37.183397 N 122.411904 W PIGEON01 - + 37.090736 N 122.348775 W ANONUV01 - + 36.929502 N 122.113725 W SCRUZ01 - + 36.934235 N 122.022130 W SCRUZ02 - + 36.960666 N 122.024734 W SCRUZENT - - 37.475062 N 122.488531 W - HMPILLPT - - + 36.581344 N 121.995411 W CYPRSSPT - + 36.301110 N 121.919097 W PTSUR - + 36.238177 N 121.855209 W COOPERPT - + 36.225175 N 121.801314 W PFEIFENT - + 36.230449 N 121.797444 W PFEIFANC - + 35.879801 N 121.498947 W SANMRT01 - + 35.652801 N 121.308485 W PDRSBLNC - + 35.623297 N 121.185920 W SNSMNENT - + 35.640478 N 121.183772 W SNSMNANC - + 35.572353 N 121.152797 W CAMBRIA - + 35.449214 N 121.020825 W PTESTERO - + 35.216602 N 120.928391 W PTBUCHON - + 34.883361 N 120.684631 W PTSAL01 - + 34.884641 N 120.652026 W PTSALENT - + 34.896555 N 120.649124 W PTSALANC - + 34.758180 N 120.642516 W PURSMAPT - + 34.572579 N 120.663636 W PTARGLLO - + 34.113844 N 120.492630 W SANMGL01 - + 34.029483 N 120.471409 W SANMGL02 - + 34.019184 N 120.444197 W SANMGL03 - + 34.023478 N 120.438209 W ADCOVENT - + 34.028615 N 120.439696 W ADCOVANC -- 2.30.2